/*****************************************************************************
 *
 * Copyright (c), 2004-2020,ShangHai Neotune Information Technology Co., Ltd.
 *
 * Module Name : snmpUtil.h
 *
 * Author :    sean
 *
 * Date :    2004-02-05
 *
 * Version :    1.00
 *
 * Description :    
 *
 * Other :    
 *
 * Data Structure List: <Main Data Structure>
 *
 * Modification History
 * ---------------------------------------------------------------------------
 *  1: Data :      2004-02-05
 *    Author :     sean
 *    Version :    V100R001M00
 *    Modification : creation
 *
*****************************************************************************/


#ifndef _INCsnmpUtilh
#define _INCsnmpUtilh

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* includes */

#include "neos_vx_win.h"

#include "asn1.h"
#include "snmp.h"
#include "auxfuncs.h"

/* defines */

#define MAX_IDB_STRING    256 /* TODO */

/* Max OID is prefix+suffix+maxSubIdCount */

#define MAX_OID_LENGTH    (OID_PREFIX_SIZE + 1 + MAX_SUBID_COUNT) 

#define COPY_OIDS(dsto, srco, cnt)    { \
                        int tmp = cnt; \
                        OIDC_T *dst = dsto, *src = srco; \
                        while(tmp--) *dst++ = *src++; \
                    }

/* Token separators */

#define    TOKEN_SP1    ':'
#define    TOKEN_SP2    ','
#define    TOKEN_EQUAL    '='
#define    TOKEN_DELIMIT        TOKEN_SP2
#define    TOKEN_DELIMIT_LAST    TOKEN_SP1

/* Copy a token separated by SP1 or SP2, into dst buffer. */

#define    GET_TOKEN(src, maxLen, dst, dstLen) { \
    dstLen = 0; \
    while (*src != TOKEN_SP1 && *src != TOKEN_SP2 && maxLen--) \
        dst[dstLen++] = *src++; \
    dst[dstLen] = 0; \
    src++; maxLen--; \
    }

/* Get a suffixId and pointer to value, from <sufxId>=<val> pair */

#define GET_SUFFIX_N_VALSTR(str, maxLen, sufx, pVal) { \
    sufx = -1; \
    pVal = str; \
    while (*pVal != TOKEN_EQUAL && maxLen--) pVal++; \
    if (maxLen >= 0) { \
        *pVal++ = 0; \
        sufx = strtol(str, NULL, 10); \
        } \
    }

/* function declarations  */

/* Interface to read MIB data maintained by Envoy internally */

IMPORT STATUS snmpMibObjHandler
    (
    idbRequest_t request, 
    idb_t *idb, 
    char *objName
    );

/* Utility functions */

IMPORT ulong_t stringConvert 
    (
    OCTET_T        *src, 
    ulong_t        maxSrc, 
    OCTET_T        *dst,
    ulong_t        maxDst
    );

IMPORT ulong_t oidConvert 
    (
    OCTET_T        *src, 
    ulong_t        maxSrc, 
    OIDC_T        *dst,
    ulong_t        maxDst
    );

IMPORT int octetToDisplayHex 
    (
    OCTET_T *nameStr, 
    ALENGTH_T nameStrLen, 
    OCTET_T *dstStr
    );

IMPORT int oidToDisplayString 
    (
    OIDC_T *pTree, 
    ALENGTH_T treeLen, 
    OCTET_T *dstStr
    );


#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* _INCsnmpUtilh */
